using System;
using System.Linq;
using System.Windows.Input;
using ScriptEase.Shell.Controls;
using ScriptEase.Shell.Events;



namespace ScriptEase.Shell.Commands
{
    internal class ExitApplicationCommand : ICommand
    {
        private readonly ShellViewModel _shellViewModel;
        private readonly WebResourceStatusView _viewModel;



        public ExitApplicationCommand(ShellViewModel shellViewModel, WebResourceStatusView viewModel)
        {
            _shellViewModel = shellViewModel;
            _viewModel = viewModel;
        }



        public void Execute(object view)
        {
            _shellViewModel.CloseApp();
        }



        public bool CanExecute(object parameter)
        {
            bool canClose = (_shellViewModel.ProjectLoadStatus != ProjectStatus.Connecting &&
                    !_viewModel.SelectedItems.Any(item => item.SyncStatus == FileSyncStatus.Publishing
                                                          && item.SyncStatus == FileSyncStatus.Updating));
            return canClose;
        }



        public event EventHandler CanExecuteChanged;
    }
}